/**
 * Created by Dell on 2016/6/30.
 */
var keys = require('../../cloud/lib/keys');
var redisServer = require('../../cloud/redis/redisServer');

exports.addLiveMem = function (liveId, userObj, cb) {
    redisServer.lpush(keys['liveMems'] + liveId, JSON.stringify(userObj), function (error, reply) {
        cb();
    })
    // redisServer.sadd(keys['liveMems']+liveId,JSON.stringify(userObj),cb);
}

exports.delLiveMem = function (liveId, userObj, cb) {
    redisServer.lrem(keys['liveMems'] + liveId, JSON.stringify(userObj), function (error, reply) {
        cb();
    })
    // redisServer.srem(keys['liveMems']+liveId,JSON.stringify(userObj),cb);
}

exports.liveMems = function (liveId, cb) {
    redisServer.lrange(keys['liveMems'] + liveId, 0, 19, function (error, reply) {
        redisServer.llen(keys['liveMems'] + liveId,function(error,count) {
            var obj = {};
            var array = [];
            if (reply) {
                for (var i = 0; i < reply.length; i++) {
                    array.push(JSON.parse(reply[i]));
                }
            }
            obj.array = array;
            obj.count = count;
            cb(error, obj);
        })
    })
    // redisServer.smembers(keys['liveMems']+liveId,function(error,mems){
    //     var returnMems = [];
    //     if(mems){
    //         for(var i=0;i<mems.length;i++){
    //             returnMems.push(JSON.parse(mems[i]));
    //         }
    //     }
    //     cb(error,returnMems);
    // });
}